<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="spring" uri="/WEB-INF/lib/spring.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib prefix="z" uri="/WEB-INF/lib/zerdoor.tld"%>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><spring:message code='task_info.title.employ' /></title>
    <link href="${path}/style/acg/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" media="screen" href="${path}/plugins/validate/validate.css">
    <script src="${path}/js/jquery.min.js" type="text/javascript"></script>
    <%--<script type="text/javascript" src="${path}/style/acg/js/common.js"></script>--%>

    <script src="${path}/plugins/validate/jquery.validate.min.js" type="text/javascript"></script>
    <c:if test="${ sessionScope.language == '' || sessionScope.language == 'zh_cn'}">
        <script src="${path}/plugins/validate/messages_cn.js" type="text/javascript"></script>
    </c:if>
    <!-- 文件上传JS -->
    <script type="text/javascript" src="${path}/js/ajaxfileupload.js"></script>

    <script type="text/javascript">

        $(function(){

            if("${curUser.userId}" == "" ){

                alert("<spring:message code='race_info.alert.tipLogin' />");
                window.location.href = "${path}/login/index.html"

                return;
            }

            f_init();
            f_backPage();

        });

        //初始化函数
        function f_init() {
            //初始化一级分类

            f_findPajectType(1, "first_class");

            $("#first_class").change(function () {
                f_findPajectType($(this).val(), "second_class");
            });

            f_saveItem();

        }


        /**级联查询分类*/
        function f_findPajectType(parent,selID){

            $.post("${path}/taskList/findTaskTypeByParent.html", { parent: parent},
                    function(data, textStatus){

                        var html = "";
                        for (i in data) {

                            var type = data[i];
                            html += "<option value='" + type.id + "' skill='"+type.skill+"'>" + type.name + "</option>";
                        }

                        $("#"+selID).html(html);

                        //如果为一级分类，则默认初始化二级分类
                        if("first_class" == selID){

                            //返回处理
                            if($("#first_class_type").val() != "" && $("#first_class_type").val() != null){
                                $("#"+selID).val($("#first_class_type").val());
                            }

                            f_findPajectType($("#"+selID).val(),"second_class");
                        }else{

                            //返回处理
                            if($("#second_class_type").val() != "" && $("#second_class_type").val() != null){
                                $("#"+selID).val($("#second_class_type").val());
                            }

                        }

                    });
        }


        //Ajax文件上传
        function f_file_upload(fileInputId){

            //var result =/\.[^\.]+/.exec($("#fulAchievements").val());

            var path = $("#"+fileInputId).val();

            var pos1 = path.lastIndexOf("\\");
            var pos2 = path.lastIndexOf(".");
            var pos = path.substring(pos1 + 1, pos2);

            var fileName = path.substring(pos1+1,pos2);

            var str = $("#"+fileInputId).val().split(".");
            var result = path.substring(pos2 + 1,path.length );

            var rars = ".rar.zip.7z.cab.txt.doc.docx.xls.xlsx.RAR.ZIP.7Z.CAB.TXT.DOC.DOCX.XLS.XLSX";

            var imgs = ".bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif.BMP.JPG.DIB.JPEG.PNG.JFIF.JPE.TIF.TIFF.GIF";

            //文件类型 false为压缩包
            var boo = false;

            //判断上传的是项目图片还是项目附件
            if("fulAchievements1" == fileInputId){
                if(imgs.indexOf(result) > -1){
                    boo = true;
//                    console.log("图片");
                }else{

                    alert(" <spring:message code='task_info.alert.upload' arguments='.bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif' argumentSeparator=','/>");
                    $("#"+fileInputId).val("");
                    return;
                }
            }else{

                if(rars.indexOf(result) > -1){
//                    console.log("压缩包");
                }else if(imgs.indexOf(result) > -1){
                    boo = true;
//                    console.log("图片");
                }else{

                    alert("<spring:message code='task_info.alert.upload2' arguments='.rar.zip.7z.cab,.bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif' argumentSeparator=','/>")
                    $("#"+fileInputId).val("");
                    return;
                }
            }

            $.ajaxFileUpload({
                url: '${path}/fileUpload/upload_resource_file.html',
                secureuri: false,
                fileElementId: fileInputId,
                //dataType: 'json',
                success: function (data) {
                    //data = $.parseJSON(data);

                    var data2 = data.split(",");

                    var url = data2[0].replace(" ","");
                    fileName = data2[1].replace(" ","");

                    var src = "${path}/style/common/images/yasuobao.png";
                    if(boo){
                        src = "${path}/"+url;
                    }

                    if("fulAchievements1" == fileInputId){
                        f_item_pic(src,url,fileName);
                    }else{
                        f_attachment(src,url,fileName);
                    }



                },
                error:function(data){

                    console.log("error");
                    console.log(data);
                }
            });
        }

        //项目图片
        function f_item_pic(src,url,fileName){

            var html = "";

            html += "<li title="+fileName+">";
            html += "<img src='"+src+"' width='56' height='70' />";
            html += "        <p>"+fileName+"</p>";

            if($("#item_pic").val() == "" && $("#item_front_cover").val() == ""){
                html += "<a onclick=\"f_setCover('"+url+"',this)\"   ><spring:message code='task_info.msg.projectCover' /></a>";

                $("#item_front_cover").val(url);



            }else if( $("#item_front_cover").val() != "" && url == $("#item_front_cover").val()) {

                html += "<a onclick=\"f_setCover('"+url+"',this)\"   ><spring:message code='task_info.msg.projectCover' /></a>";

            }else{

                html += "<a onclick=\"f_setCover('"+url+"',this)\"   ><spring:message code='task_info.msg.makeCover' /></a>";
            }

            html += "</li>";

            //设置值
            $("#item_pic").val($("#item_pic").val()+ url + "," );
            //显示
            $("#item_pic_ul").html($("#item_pic_ul").html() + html);



        }
        //项目附件
        function f_attachment(src,url,fileName){
            var html = "";

            html += "<li>";
            html += "<img src='"+src+"' width='56' height='70' />";
            html += "        <p>"+fileName+"</p>";


            html += "</li>";

            //设置值
            $("#attachment").val($("#attachment").val()+ url + "," );
            //显示
            $("#attachment_ul").html($("#attachment_ul").html() + html);
        }

        //设置为封面
        function f_setCover(url,obj){


            $("#item_pic_ul").find("a").each(function(){

                $(this).html("<spring:message code='task_info.msg.makeCover' />")
            });

            $("#item_front_cover").val(url);

            $(obj).html("<spring:message code='task_info.msg.projectCover' />");

        }

        //保存项目信息
        function f_saveItem(){



            var validate = $("#taskForm").validate({
                ignore: [],
                rules : {
                    title:{
                        required: true
                    },
                    description:{
                        required: true
                    },
                    item_front_cover:{

                        required: true
                    },

                    budget:{
                        required: true,
                        number: true,
                        min:0
                    }
                },
                messages : {

                },

                success: function(label) {//验证成功添加样式
                    label.html("&nbsp;").removeClass("checked").addClass("checked");
                },
                submitHandler : function(){
                    $.post("${path}/employArtistTask/insertTaskInfo.html",
                            $("#taskForm").serialize()
                            ,function(data){
                                if(data != "error"){

                                    $("#item_id").val(data);


                                    //赋值给临时表单
                                    $("#first_class_type").val($("#first_class").val());
                                    $("#second_class_type").val($("#second_class").val());

                                    window.location = "${path}/employArtistTask/confirmTaskInfo.html?taskId="+data;
                                }else{
                                    alert("<spring:message code='task_info.alert.msg1' />");
                                }
                            },"json");
                }

            });


            <%--$.post("${path}/taskInfo/insertTaskInfo.html",--%>
                    <%--$("#taskForm").serialize()--%>
                    <%--,function(data){--%>
                        <%--if(data != "error"){--%>
                            <%--//alert("<spring:message code="bid.result_success"/>");--%>
                            <%--$("#item_id").val(data);--%>


                            <%--//还原下拉框为不可点击--%>
                            <%--if(!boo_is_deposit){--%>
                                <%--$("#is_deposit").attr("disabled");--%>
                            <%--}--%>
                            <%--if($("#budget").val() == "-1"){--%>
                                <%--$("#budget").attr("disabled");--%>

                            <%--}--%>
                            <%--if(!boo_piece_num){--%>
                                <%--$("#piece_num").attr("disabled");--%>
                            <%--}--%>

                            <%--//赋值给临时表单--%>
                            <%--$("#first_class_type").val($("#first_class").val());--%>
                            <%--$("#second_class_type").val($("#second_class").val());--%>

                            <%--window.location = "${path}/taskInfo/confirmTaskInfo.html?taskId="+data;--%>
                        <%--}else{--%>
                            <%--// alert("<spring:message code="bid.result_fail"/>");--%>
                        <%--}--%>
                    <%--},"json");--%>


        }


        //处理从上一页返回回来的操作
        function f_backPage(){

            //如何item_id为空，那么就默认不处理
            if($("#item_id").val() == ""){
                return;
            }

            //取出隐藏表单中的值
            var item_pic = $("#item_pic").val();
            var item_front_cover = $("#item_front_cover").val();
            var attachment = $("#attachment").val();

            //赋空值
            $("#item_pic").val("");
            $("#item_front_cover").val("");
            $("#attachment").val("");

            //处理项目图片
            var item_pic_arr = item_pic.split(",");
            for(var i in item_pic_arr){

                if(item_pic_arr[i] != ""){

                    var src = "${path}/" + item_pic_arr[i];
                    var url = item_pic_arr[i];
                    var fileName = item_pic_arr[i].replace(/^.*[\\\/]/, '');

                    f_item_pic(src,url,fileName);
                }

            }

            //处理附件
            var attachment_arr = attachment.split(",");
            for(var i in attachment_arr){

                if(attachment_arr[i] != ""){

                    var src = "${path}/" + attachment_arr[i];
                    var url = attachment_arr[i];
                    var fileName = attachment_arr[i].replace(/^.*[\\\/]/, '');

                    var path = url;
                    var pos1 = path.lastIndexOf("\\");
                    var pos2 = path.lastIndexOf(".");
                    var pos = path.substring(pos1 + 1, pos2);
                    //var fileName = path.substring(pos1+1,pos2);
                    var str = url.split(".");
                    var result = path.substring(pos2 + 1,path.length );
                    var rars = ".rar.zip.7z.cab.txt.doc.docx.xls.xlsx.RAR.ZIP.7Z.CAB.TXT.DOC.DOCX.XLS.XLSX";


                    if(rars.indexOf(result) > -1) {
                        //console.log("压缩包");

                        src = "${path}/style/common/images/yasuobao.png";
                    }
                    f_attachment(src,url,fileName);
                }

            }


        }


    </script>
</head>

<body>
<div class="header">
    <jsp:include page="../public/header.jsp">
        <jsp:param    name="home"    value="dddd"    />
    </jsp:include>
</div>

<div id="container">
    <div class="wrapper">
    	<div class="referbidbox">
        	<div class="refer_step step1">
            	<ul>
                    <li class="now"><spring:message code='task_info.msg.descriptionDemand' /></li>
                    <li><spring:message code='task_info.msg.identificationOfNeeds' /></li>
                    <li class="last"><spring:message code='task_info.msg.demandRelease' /></li>
                </ul>
            </div>
        	<div class="referform nomorder">
                <form id="taskForm" name="taskForm"  method="POST">
                    <input type="hidden" id="item_id" name="item_id"/>
            	<ul>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt><spring:message code='task_info.msg.msg1' /></dt>
                            <dd>
                            	<label class="color_red">${initDataMap.userInfo.real_name}</label>
                            	<label>
                                    <a href="${path}/usercenter/toUserMessagesHome.html?sender=${initDataMap.userInfo.user_id}" value="${initDataMap.userInfo.user_id}" class="deltail_lxwm"><em class="icon"><spring:message code='task_info.msg.msg2' /></em></a>
                                    <input type="hidden" value="${initDataMap.userInfo.artist_id}" name="artist_id" >
                                </label>
                            </dd>
                        </dl>
                    </li>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt><spring:message code='task_info.msg.projectTitle' /></dt>
                            <dd><input type="text" name="title" id="title" value="" class="input_txt" /></dd>
                        </dl>
                    </li>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt><spring:message code='task_info.msg.itemDescription' /></dt>
                            <dd><textarea class="text_con" id="description" name="description"></textarea></dd>
                        </dl>
                    </li>
                    <li class="formli">
                        <dl class="clearfix">
                            <dt><spring:message code='task_info.msg.projectPictures' /></dt>
                            <dd>
                                <div class="project_files">
                                    <ul class="clearfix" id="item_pic_ul">


                                    </ul>
                                </div>
                            </dd>
                        </dl>
                    </li>
                    <li class="formli">
                        <dl class="clearfix">
                            <dt>&nbsp;</dt>
                            <dd>
                                <input type="button" name="" onclick="javascript:$(this).next().trigger('click')" class="addgrey_btn" value="<spring:message code='task_info.button.addItemPicture' />" />
                                <input  type="file" style="display: none;" name="file" id="fulAchievements1" onchange="f_file_upload('fulAchievements1')" />
                                <input type="hidden" name="item_pic" id="item_pic" />
                                <input type="hidden" name="item_front_cover" id="item_front_cover" />
                                <label id="item_pic_msg"></label>
                            </dd>
                        </dl>
                    </li>
                    <li class="formli">
                        <dl class="clearfix">
                            <dt><spring:message code='task_info.msg.postAttachments' /></dt>
                            <dd>
                                <div class="project_files">
                                    <ul class="clearfix" id="attachment_ul">

                                    </ul>
                                </div>
                            </dd>
                        </dl>
                    </li>
                    <li class="formli">
                        <dl class="clearfix">
                            <dt>&nbsp;</dt>
                            <dd>
                                <input type="button" name="" onclick="javascript:$(this).next().trigger('click')" class="addgrey_btn" value="<spring:message code='task_info.button.addAttachments' />" />
                                <input style="display: none" type="file" name="file" id="fulAchievements2" onchange="f_file_upload('fulAchievements2')">
                                <input type="hidden" name="attachment" id="attachment" value="">

                            </dd>
                        </dl>
                    </li>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt><spring:message code='task_info.msg.category' /></dt>
                            <dd class="clearfix">
                                <select name="first_class" id="first_class" class="select">

                                </select>
                                <select name="second_class" id="second_class" class="select">

                                </select>

                                <input type="hidden" id="first_class_type" value="">
                                <input type="hidden" id="second_class_type" value="">
                            </dd>
                        </dl>
                    </li>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt><spring:message code='task_info.msg.demandStyle' /></dt>
                            <dd class="clearfix">
                                <select name="style" id="style" class="select">

                                    <c:forEach items="${initDataMap.styleList}" var="style">
                                        <option value="${style.id}">${style.name}</option>
                                    </c:forEach>

                                </select>
                             </dd>
                        </dl>
                    </li>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt><spring:message code='task_info.msg.tenderPrices' /></dt>
                            <dd class="clearfix">

                                <input type="text" id="budget"  name="budget" value="0" class="money_input w233"  />
                                <label class="grey"><spring:message code='task_info.msg.msg3' /></label>
                             </dd>
                        </dl>
                    </li>
                	<li class="formli">
                    	<dl class="clearfix">
                        	<dt>&nbsp;</dt>
                            <dd class="clearfix">
                            	<input type="submit" id="" name="" value="<spring:message code='task_info.button.next' />" class="submitnext" />
                             </dd>
                        </dl>
                    </li>
                </ul>
                </form>
            </div>

        </div>
    </div>
</div>
<div id="footer">
    <!--content-->
    <jsp:include page="../public/footer.jsp"></jsp:include>
</div>

</body>
</html>